


package com.hazelcast.function;

import com.hazelcast.internal.util.ExceptionUtil;

import javax.annotation.Nullable;
import java.util.function.Consumer;

/**
 * A {@link Consumer} that declares checked exception.
 *
 * @param <T> type of consumed item
 * @since 6.0
 */
@FunctionalInterface
public interface ThrowingConsumer<T> extends Consumer<T> {

    /**
     * Consumes given item.
     *
     * @see Consumer#accept(Object)
     */
    void acceptEx(@Nullable T item) throws Exception;

    @Override
    default void accept(T item) {
        try {
            acceptEx(item);
        } catch (Exception e) {
            throw ExceptionUtil.sneakyThrow(e);
        }
    }
}
